
<!DOCTYPE html>
<html>

	<head>
		<meta charset="UTF-8">
		<title>添加收货地址</title>
		<meta http-equiv="X-UA-Compatible" content="IE=edge">
		<meta http-equiv="Cache-Control" content="no-transform">
		<meta name="format-detection" content="telephone=no">
		<meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=no">
		<link rel="stylesheet" href="style/css/basic.css">
		<link rel="stylesheet" href="style/css/edit_address.css" />
		<script type="text/javascript" src="style/plugin/mui/js/mui.min.js"></script>
		<script type="text/javascript" src="style/js/jquery-1.8.3.min.js"></script>
		<script type="text/javascript" src="style/js/vue.min.js"></script>
		<script type="text/javascript" src="style/js/vue-resource.js"></script>
		<script type="text/javascript" src="style/js/md5.js"></script>
		<script type="text/javascript" src="style/js/basic.js"></script>
		<script type="text/javascript" src="style/js/form.js" ></script>
		<script src="style/citypicker/js/common.js"></script>
		<script src="style/citypicker/js/Popt.js"></script>
		<script src="style/citypicker/js/cityJson.js"></script>
		<script src="style/citypicker/js/citySet.js"></script>
	</head>

	<body>
		<div id="edit">
		    <div id="header">
				<h1>编辑收货地址</h1>
				<span class="backicon"></span>
				<span class="righttxt" @tap="storeAddr">保存</span> 
			</div>
			<div class="body">
				<form method="post">
					<div class="add">				
						<div>
							<label>收货人 </label>
							<input type="text" name="name" placeholder="收货人姓名" required v-model="uname"/>
							<i class="clear_input"></i>
						</div>
						<div>
							<label>手机号 </label>
							<input type="tel" name="tel" placeholder="手机号码" required maxlength="11" v-model="uphone"/>
							<i class="clear_input"></i>
						</div>
						<div data-role="page" id="test">
							<div class="ui-content">
								<ul data-role="listview">
									<li>
										<label>所在地区</label>
										<input type="text" name="city" placeholder="所在地区" id="city" readonly/>
									</li>
								</ul>
							</div>
						</div>
						<div>
							<label>详细地址 </label>
							<input type="text" name="city" placeholder="如道路、门牌号、小区等" required v-model="deladdr"/>
							<i class="clear_input"></i>
						</div>
						<div class="default">
							<label>设为默认地址</label>
							<input type="checkbox" id="" class="switch" @tap="editAddr">
						</div>
						<div class="default">
							<label class="text_color">删除收货地址</label>
						</div>				
					</div>
				</form>
			</div>	
		</div>
		
		
	</body>
	<script type="text/javascript">
		$("#city").click(function(e) {
			SelCity(this, e);
			console.log(this);
		});
		new Vue({
			el:"#edit",
			data:{
				adrMsg:"",
				uname:"",
				uphone:"",
				deladdr:"",
				flag:0,
				ticket:"",
				sign:""
			},
			methods:{
				editAddr:function(){ 
    				var that=this
    				that.flag==0?that.flag=1:that.flag=0
    				mui.plusReady(function(){
    					var selfaddr=plus.webview.currentWebview().current
    					that.$http.post(domain+"/member_address/setDefault?t="+that.ticket+"&sign="+that.sign,{
	    					id:selfaddr
	    				},{emulateJSON:true}).then(//获取轮播图
				            function (res) {
				                // 处理成功的结果
				                if(res.body.code==1){
				                  console.log(res.body)	
				                  mui.toast("设置成功")
				                } 
				            },function (res) {
				            // 处理失败的结果
				            console.log(res) 
				            }
				        );
    				})
    				
				},
				storeAddr:function(){
//					alert(1)
					var a=sessionStorage.getItem("province");
    				var b=sessionStorage.getItem("city")
    				var c=sessionStorage.getItem("county")
    				var that=this;
    				mui.plusReady(function(){
    					var selfaddr=plus.webview.currentWebview().current
    					that.$http.post(domain+"/member_address/save?t="+that.ticket+"&sign="+that.sign,{
	    					id:selfaddr,
	    					name:that.uname,
	    					phone:that.uphone,
	    					province_id:a,
				    		city_id:b,
				    		area_id:c,
				    		address:that.deladdr,
				    		is_default:that.flag
	    				},{emulateJSON:true}).then(//获取轮播图
				            function (res) {
				                // 处理成功的结果
				                if(res.body.code==1){
				                  console.log(res.body)	
				                  mui.toast("保存成功")
				                } 
				            },function (res) {
				            // 处理失败的结果
				            console.log(res) 
				            }
				        );
    				})
    				
				}
			},
			created:function(){
				this.ticket=localStorage.getItem("tick")
                this.sign=localStorage.getItem("sig")
                var that=this
                mui.plusReady(function(){
					that.addId=plus.webview.currentWebview().current
					that.$http.post(domain+"/member_address/getInfo?t="+that.ticket+"&sign="+that.sign,{
						id:that.addId
					},{emulateJSON:true}).then(//获取轮播图
			            function (res) {
			                // 处理成功的结果
			                if(res.body.code==1){
			                  console.log(res.body)	
			                  
			                } 
			            },function (res) {
			            // 处理失败的结果
			            console.log(res) 
			            }
			        );
				})
			},
			mounted:function(){
				 mui.plusReady(function(){  
	                var old_back = mui.back;  
	                mui.back = function() {  
	                    var wobj = plus.webview.getWebviewById("address.html"); //返回的页面
	                    wobj.reload(true);  
	                    old_back()  
	                }     
	            });

			}
		})
	</script>

</html>